package com.woniu.service.impl;

import com.woniu.entity.MaterialRequisition;
import com.woniu.entity.ProductInput;
import com.woniu.mapper.MaterialRequisitionMapper;
import com.woniu.mapper.ProductInputMapper;
import com.woniu.service.MaterialRequisitionService;
import com.woniu.util.ResponseEnum;
import com.woniu.util.ResponseUtil;
import com.woniu.vo.RequisitionVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class MaterialRequisitionServiceImpl implements MaterialRequisitionService {
    @Resource
    private MaterialRequisitionMapper mapper;

    @Override
    public ResponseUtil findAll() {
        List<MaterialRequisition> list = mapper.findAll();
        return !list.isEmpty() ? ResponseUtil.get(ResponseEnum.OK, list)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
    @Override
    public ResponseUtil findByRequisitionId(Integer requisitionId) {
        MaterialRequisition obj = mapper.findByRequisitionId(requisitionId);
        return obj != null ? ResponseUtil.get(ResponseEnum.OK, obj)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
    @Override
    public ResponseUtil add(MaterialRequisition materialRequisition) {
        return mapper.add(materialRequisition) > 0
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
    @Override
    public ResponseUtil delete(Integer requisitionId) {
        return mapper.delete(requisitionId) > 0
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
    @Override
    public ResponseUtil update(MaterialRequisition materialRequisition) {
        return mapper.update(materialRequisition) > 0
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }



    @Override
    public ResponseUtil queryVoList() {
        List<RequisitionVo> list = mapper.findByStatus();
        return !list.isEmpty() ? ResponseUtil.get(ResponseEnum.OK, list)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
}
